$(function(){
	var province2=allarea()
	console.log(province2)
	var page=1;
	var tddata=[
		{
			key:'name',
			type:1,
			url:''
		},{
			key:'phone',
			type:1,
			url:'{:url("detail")}',
			id:137
		},{
			key:'birthday',
			type:1,
			url:''
		},{
			key:'age',
			type:1,
			url:''
		},{
			key:'sex2',
			type:1,
			url:''
		},{
			key:'occupation',
			type:1,
			url:''
		},
		{
			key:'source',
			type:1,
			url:''
		},
		{
			key:'id_number',
			type:1,
			url:''
		},{
			key:'company_name',
			type:1,
			url:''
		},
		{
			key:'department_name',
			type:1,
			url:''
		},
		{
			key:'live_number',
			type:1,
			url:''
		},
		{
			key:'province2',
			type:1,
			url:''
		},
		{
			key:'is_check2',
			type:1,
			url:''
		},{
			key:'is_instead2',
			type:1,
			url:''
		},
		{
			key:'is_vip2',
			type:1,
			url:''
		}];
	
	var addoperation=``;
	var fields='';
	
	var data={
		page:1,
		pagenum:10
	}
	
	var where_json={}
	{if $Think.get.name}
		where_json.name=['like','%{$Think.get.name}%']
	{/if}
	{if $Think.get.phone}
		where_json.phone=['like','%{$Think.get.phone}%']
	{/if}
	{if $Think.get.company_name}
		where_json.company_name=['like','%{$Think.get.company_name}%']
	{/if}
	{if $Think.get.is_check}
		where_json.is_check=['in','{$Think.get.is_check}']
	{/if}
	
	data.where_json=JSON.stringify(where_json)
	ajaxpassenger(data)
	function ajaxpassenger(data){
		Load()
		$.ajax({
			type:'post',
			data:data,
			url:'{:url("adminapi/Passenger/passengerList")}',
			success:function(res){
				Load(1)
				console.log(res)
				if(res.code==1){
					for(var i=0;i<res.data.length;i++){
						if(res.data[i].sex==1){
							res.data[i].sex2='男'
						}else{
							res.data[i].sex2='女'
						}
						if(res.data[i].is_check==1){
							res.data[i].is_check2='是'
						}else{
							res.data[i].is_check2='否'
						}
						if(res.data[i].is_instead==1){
							res.data[i].is_instead2='是'
						}else{
							res.data[i].is_instead2='否'
						}
						if(res.data[i].is_vip==1){
							res.data[i].is_vip2='是'
						}else{
							res.data[i].is_vip2='否'
						}
	//判断省市县
						if(res.data[i].province){
							res.data[i].province2=province2[res.data[i].province].name
							
							if(res.data[i].city){
								var ival = parseInt(res.data[i].city)
								if(!isNaN(ival)){
									console.log(res.data[i].city)
									res.data[i].province2+=province2[res.data[i].province].city[res.data[i].city].name
									if(res.data[i].district){
										var ival2 = parseInt(res.data[i].district)
										if(!isNaN(ival2)){
											res.data[i].province2+=province2[res.data[i].province].city[res.data[i].city].district[res.data[i].district].name
										}
									}
								}
	//							
								
							}
						}
						 
					}
//					$('tbody').html(tbodymainf2(res.data, 1, tddata, addoperation, 'driver_id'))
					console.log(res.data)
					layui.use('table', function(){
					  	var table = layui.table;
					 //展示已知数据
					 	 table.render({
					    	elem: '#passenger'
						    ,cols: [[ //标题栏
						      {field: 'name', title: '姓名', width: 150, sort: true,fixed: 'left'}
						      ,{field: 'phone', title: '手机号', width: 150,fixed: 'left'}
						      ,{field: 'birthday', title: '出生年月', minWidth: 150}
						      ,{field: 'age', title: '年龄', minWidth: 150}
						      ,{field: 'sex2', title: '性别', width: 180}
						      ,{field: 'occupation', title: '职业', minWidth: 150}
						      ,{field: 'source', title: '来源', minWidth: 150}
						      ,{field: 'id_number', title: '身份证', width: 150}
						      ,{field: 'company_name', title: '公司/单位', minWidth: 150}
						      ,{field: 'department_name', title: '部门', minWidth: 150}
						      ,{field: 'live_number', title: '居住证', width: 150}
						      ,{field: 'province2', title: '所在城市及县区', minWidth: 150}
						      ,{field: 'is_check2', title: '审核员', minWidth: 150}
						      ,{field: 'is_instead2', title: '代打车', width: 150}
						      ,{field: 'is_vip2', title: 'vip', minWidth: 150}
						      
						    ]]
						    ,data:res.data
						    //,skin: 'line' //表格风格
						    ,even: true
						    //,page: true //是否显示分页
						    //,limits: [5, 7, 10]
						    //,limit: 5 //每页默认显示的数量
					  	});
						$('.pagination').html(pagechang1(res.count, 10, page))
						$('.laquo').on('click',function(){
							console.log(data)
							page-=1;
							data.page=page
							ajaxpassenger(data)
						})
						$('.pageli').on('click',function(){
							console.log(data)
							page=$(this).html()
							data.page=page
							ajaxpassenger(data)
						})
						//下一页
						$('.raquo').on('click',function(){
							console.log(data)
							page+=1;
							data.page=page
							ajaxpassenger(data)
						});
					})
					$('.daochu').on('click',function(){
						var getkey="";
	//					for(var key in res.description){
	//						getkey+=`<li>
	//									<label class="am-checkbox">
	//								      <input type="checkbox" value="" data-key='${key}' checked> ${res.description[key].name}
	//								    </label>
	//								</li>`
	//					}
						
	
						for(var iii=0;iii<tddata.length;iii++){
							if(tddata[iii].key=='sex2'){
								for(var key in res.description){
									if(key=='sex'){
										tddata[iii].text=res.description[key].name
									}
								}
								getkey+=`<li>
										<label class="am-checkbox">
									      <input type="checkbox" value="" data-key='sex' checked> ${tddata[iii].text}
									    </label>
									</li>`
							}else if(tddata[iii].key=='province2'){
								for(var key in res.description){
									if(key=='province'){
										tddata[iii].text=res.description[key].name
									}
								}
								getkey+=`<li>
										<label class="am-checkbox">
									      <input type="checkbox" value="" data-key='province' checked> ${tddata[iii].text}
									    </label>
									</li>`
							}else if(tddata[iii].key=='is_check2'){
								for(var key in res.description){
									if(key=='is_check'){
										tddata[iii].text=res.description[key].name
									}
								}
								getkey+=`<li>
										<label class="am-checkbox">
									      <input type="checkbox" value="" data-key='is_check' checked> ${tddata[iii].text}
									    </label>
									</li>`
							}else if(tddata[iii].key=='is_instead2'){
								for(var key in res.description){
									if(key=='is_instead'){
										tddata[iii].text=res.description[key].name
									}
								}
								getkey+=`<li>
										<label class="am-checkbox">
									      <input type="checkbox" value="" data-key='is_instead' checked> ${tddata[iii].text}
									    </label>
									</li>`
							}else if(tddata[iii].key=='is_vip2'){
								for(var key in res.description){
									if(key=='is_vip'){
										tddata[iii].text=res.description[key].name
									}
								}
								getkey+=`<li>
										<label class="am-checkbox">
									      <input type="checkbox" value="" data-key='is_vip' checked> ${tddata[iii].text}
									    </label>
									</li>`
							}else{
								for(var key in res.description){
									if(key==tddata[iii].key){
										tddata[iii].text=res.description[key].name
									}
								}
								getkey+=`<li>
										<label class="am-checkbox">
									      <input type="checkbox" value="" data-key='${tddata[iii].key}' checked> ${tddata[iii].text}
									    </label>
									</li>`
							}
							
						}
						layer.open({
						  	type: 1,
						  	title:false,
						  	skin: 'layui-layer-rim', //加上边框
						  	area: ['300px', '400px'], //宽高
						  	content: `<div>
						 				<div style='height:300px;overflow:auto;margin-bottom:30px'>
									  	<ul class='daochuul'>${getkey}</ul>
									  	</div>
									  	<div style='text-align:center'>
									  		<button class='am-btn am-btn-sm am-btn-primary am-radius daochu_ok' type='button'>确定导出</button>
									  		<button class='am-btn am-btn-sm am-btn-primary am-radius' type='button'>取消</button>
									  	</div>
									</div>`,
							success:function(){
								var ddata={}
								$('.daochu_ok').on('click',function(){
	//								window.open('{:url("/adminapi/Order/downLoadOrderList")}')
									ddata.fields="";
									var where_jsondao={};
									
									{if $Think.get.name}
										where_jsondao.name=['like','%{$Think.get.name}%']
									{/if}
									{if $Think.get.phone}
										where_jsondao.phone=['like','%{$Think.get.phone}%']
									{/if}
									{if $Think.get.company_name}
										where_jsondao.company_name=['like','%{$Think.get.company_name}%']
									{/if}
									{if $Think.get.is_check}
										where_jsondao.is_check=['in','{$Think.get.is_check}']
									{/if}
									ddata.where_json=JSON.stringify(where_jsondao)
									
									$('.daochuul li input[type="checkbox"]').each(function(){
										if(this.checked){
											ddata.fields+=($(this).data('key')+",")
										}
									})
									ddata.fields=ddata.fields.slice(0,ddata.fields.length-1)
									console.log(ddata.fields)
									
									window.open(`{:url("adminapi/Passenger/downLoadPassengerList")}??where_json=${ddata.where_json}&fields=${ddata.fields}`)
	//								
								})
								
							}
						});
					})
				}else{
					Err(res.msg)
				}
			},
			error:function(){
				Err('请求失败')
			}
		})
	}
})
